Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.Win32
Imports System.IO


Public Class flussi
    Inherits System.Web.UI.Page

    Dim RelationColumn As String = "IDFlusso"
    Dim ParentTable As String = "FlussiMav"
    Protected WithEvents SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter
    Protected WithEvents SqlSelectCommand1 As System.Data.SqlClient.SqlCommand
    Protected WithEvents SqlConnection2 As System.Data.SqlClient.SqlConnection
    Protected WithEvents SqlDataAdapter2 As System.Data.SqlClient.SqlDataAdapter
    Protected WithEvents SqlSelectCommand2 As System.Data.SqlClient.SqlCommand
    Protected WithEvents DsFlussi1 As dsFlussi
    'Protected WithEvents Button1 As System.Web.UI.HtmlControls.HtmlInputButton
    Dim ChildTable As String = "pagamentiQuote"
    'Protected WithEvents UcTestata1 As ucTestata

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter
        Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand
        Me.SqlConnection2 = New System.Data.SqlClient.SqlConnection
        Me.SqlDataAdapter2 = New System.Data.SqlClient.SqlDataAdapter
        Me.SqlSelectCommand2 = New System.Data.SqlClient.SqlCommand
        Me.DsFlussi1 = New dsFlussi
        CType(Me.DsFlussi1, System.ComponentModel.ISupportInitialize).BeginInit()

        Me.SqlConnection2.ConnectionString = ConfigurationSettings.AppSettings("ConnString")
        '
        'SqlDataAdapter1
        '
        Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
        Me.SqlDataAdapter1.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "FlussiMav", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("id", "id"), New System.Data.Common.DataColumnMapping("Data_Creazione", "Data_Creazione"), New System.Data.Common.DataColumnMapping("Nome_Supporto", "Nome_Supporto"), New System.Data.Common.DataColumnMapping("Descrizione", "Descrizione"), New System.Data.Common.DataColumnMapping("Anno", "Anno")})})
        '
        'SqlSelectCommand1
        '
        Me.SqlSelectCommand1.Connection = Me.SqlConnection2
        '
        'SqlDataAdapter2
        '
        Me.SqlDataAdapter2.SelectCommand = Me.SqlSelectCommand2
        Me.SqlDataAdapter2.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "PagamentiQuote", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("Id", "Id"), New System.Data.Common.DataColumnMapping("IdFlusso", "IdFlusso"), New System.Data.Common.DataColumnMapping("Codice_Fiscale", "Codice_Fiscale"), New System.Data.Common.DataColumnMapping("Cognome", "Cognome"), New System.Data.Common.DataColumnMapping("Nome", "Nome"), New System.Data.Common.DataColumnMapping("Importo", "Importo"), New System.Data.Common.DataColumnMapping("Data_Scadenza", "Data_Scadenza"), New System.Data.Common.DataColumnMapping("Pagato", "Pagato"), New System.Data.Common.DataColumnMapping("Data_Pagamento", "Data_Pagamento"), New System.Data.Common.DataColumnMapping("Indirizzo", "Indirizzo"), New System.Data.Common.DataColumnMapping("Localita", "Localita"), New System.Data.Common.DataColumnMapping("Provincia", "Provincia"), New System.Data.Common.DataColumnMapping("CAP", "CAP")})})
        '
        'SqlSelectCommand2
        '
        Me.SqlSelectCommand2.CommandText = "SELECT PagamentiQuote.Id, Codice_Fiscale, Cognome, Nome, Importo,convert(char(10)" & _
        ",Data_Scadenza,103) as  Data_Scadenza, Pagato,convert(char(10),Data_Pagamento,10" & _
        "3) as  Data_Pagamento, TipoPagamentoQuote.descrizione as Tipo_Pagamento, causale" & _
        ", Indirizzo, Localita, Provincia, CAP FROM PagamentiQuote left JOIN TipoPagament" & _
        "oQuote ON PagamentiQuote.Tipo_Pagamento = TipoPagamentoQuote.codice order by cog" & _
        "nome, nome"
        Me.SqlSelectCommand2.Connection = Me.SqlConnection2
        '
        'DsFlussi1
        '
        Me.DsFlussi1.DataSetName = "dsFlussi"
        Me.DsFlussi1.Locale = New System.Globalization.CultureInfo("en-US")
        CType(Me.DsFlussi1, System.ComponentModel.ISupportInitialize).EndInit()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        populateDataSet()
        If (Not Me.IsPostBack) Then

            If Not UcTestata1.carica() Then
                Response.Redirect("..\errore.htm")
            End If

        End If
        'Put user code to initialize the page here
    End Sub
    Private Sub populateDataSet()
        SqlDataAdapter1.Fill(DsFlussi1, ParentTable)
        SqlDataAdapter2.Fill(DsFlussi1, ChildTable)

        Dim valueListAdapter As New SqlClient.SqlDataAdapter("select * from tipoPagamentoQuote", SqlConnection2)
        valueListAdapter.Fill(DsFlussi1, "TipoPagamento")

        If (DsFlussi1.Relations.Count < 1) Then DsFlussi1.Relations.Add(DsFlussi1.Tables(ParentTable).Columns("id"), DsFlussi1.Tables(ChildTable).Columns(RelationColumn))

    End Sub

 



    ''Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick
    ''    importaFlusso()

    ''    populateDataSet()

    ''    UltraWebGrid1.DataSource = DsFlussi1.Tables(ParentTable).DefaultView
    ''    UltraWebGrid1.DataBind()

    ''    Button1.Visible = False
    ''End Sub

    ''Private Sub importaFlusso()
    ''    Dim tx As TextReader
    ''    Dim sLine As String
    ''    Dim nomeSupporto As String
    ''    Dim nomeFile As String
    ''    Dim cf As String
    ''    Dim pagato As String
    ''    Dim dataPag As String

    ''    Dim dirs As String() = Directory.GetFiles(System.Configuration.ConfigurationSettings.AppSettings("sPathMav"), "*")
    ''    Dim pathFatti As String = System.Configuration.ConfigurationSettings.AppSettings("sPathMav") & "\Fatto\"
    ''    Dim dir As String
    ''    Dim obj As New cFlusso


    ''    For Each dir In dirs
    ''        tx = File.OpenText(dir)
    ''        nomeFile = Path.GetFileName(dir)

    ''        'record di testa
    ''        sLine = tx.ReadLine
    ''        nomeSupporto = Mid(sLine, 20, 20)

    ''        obj.nomeSupporto = nomeSupporto

    ''        obj.trovaFlusso()

    ''        If Not obj.id Is Nothing Then
    ''            sLine = tx.ReadLine

    ''            While Not sLine Is Nothing

    ''                While Left(sLine, 3) <> " 070"
    ''                    If Left(sLine, 3) = " 14" Then
    ''                        dataPag = Mid(sLine, 23, 6)
    ''                        pagato = Mid(sLine, 29, 5)
    ''                    End If
    ''                    If Left(sLine, 3) = " 30" Then
    ''                        cf = Mid(sLine, 71, 16)
    ''                    End If
    ''                    sLine = tx.ReadLine
    ''                    If sLine Is Nothing Then Exit While
    ''                End While


    ''                obj.CF = cf
    ''                obj.dataPag = "20" & Right(dataPag, 2) & "/" & Mid(dataPag, 3, 2) & "/" & Left(dataPag, 2)
    ''                obj.pagato = IIf(pagato = "07000", True, False)
    ''                Select Case pagato
    ''                    Case "07000"
    ''                        obj.causale = "disposizione pagata"
    ''                    Case "07006"
    ''                        obj.causale = "disposizione resa al carico"
    ''                    Case "07008"
    ''                        obj.causale = "disposizione richiamata"
    ''                    Case "07010"
    ''                        obj.causale = "disposizione radiata"
    ''                    Case "07011"
    ''                        obj.causale = "disp. pagata succ. alla radiazione"
    ''                End Select
    ''                obj.aggiornaPagamento()

    ''                If Not sLine Is Nothing Then sLine = tx.ReadLine
    ''            End While

    ''        End If

    ''        tx.Close()

    ''        'sposto il file nella dir "fatti"
    ''        File.Move(dir, pathFatti & nomeFile)
    ''    Next



    ''End Sub
End Class
